package com.belf.console.agent.migrate;

import com.alibaba.fastjson2.JSONObject;
import com.belf.common.core.domain.AjaxResult;
import com.belf.common.utils.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * JobPush
 *
 * @author l
 * @since 2024/7/19 14:09
 */

public class JobPush {

    private static final Logger logger = LoggerFactory.getLogger(JobPush.class.getName());

    /**
     *  连接引擎 提交任务
     * @param APIPath
     * @param jsonString
     * @return
     */
    public static AjaxResult pushTask(String APIPath, String jsonString){

        if(APIPath != null && jsonString != null){
            try {
                String result = HttpUtils.postJson(APIPath, jsonString);
                if (result != null){
                    AjaxResult success = AjaxResult.success(JSONObject.parseObject(result));
                    success.put("conf",jsonString);
                    return success;
                }
            } catch (IOException e) {
                logger.error("数据源信息 连接测试失败",e);
            }
        }
        AjaxResult error = AjaxResult.error();
        error.put("conf",jsonString);
        return error;
    }

    public static JSONObject pushJobManage(String APIPath, String jsonString){

        if(APIPath != null && jsonString != null){
            try {
                String result = HttpUtils.postJson(APIPath, jsonString);
                if (result != null){
                    return JSONObject.parseObject(result);
                }
            } catch (IOException e) {
                logger.error("数据源信息 连接测试失败",e);
            }
        }
        return null;
    }
}
